package protocol.chat;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.HashMap;

import config.SystemDefine;

import protocol.BasicProtocol;
import protocol.Iprotocol;
import util.KPrintInfo;
import util.ProtocolUtils;

public class Chat_protocol extends BasicProtocol implements Iprotocol {
	
	private int		from_user_id=0;
	private int		to_user_id=0;
	private int		operate=0;
	private String	content="";
	
	public Chat_protocol() {
		Type = SystemDefine.getInstance().getChatId();
	}
	
	@Override
	public void setType(int Type) {
		this.Type = Type;
	}
	
	@Override
	public int getType() {
		return this.Type;
	}
	
	public void read() {
		
	}
	
	@Override
	public byte[] write() {
		byte[] contentbytArr = content.getBytes();
		// ByteArrayOutputStream
		ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
		outputStream.write(Type);
		outputStream.write(operate);
		outputStream.write(to_user_id);
		outputStream.write(from_user_id);
		
		try {
			outputStream.write(contentbytArr);
		} catch (IOException e) {
			e.printStackTrace();
			KPrintInfo.println("Chat_protocol--write" + e.getMessage());
		}
		return outputStream.toByteArray();
	}
	
	public String getContent() {
		return content;
	}
	
	public void setContent(String content) {
		this.content = content;
	}
	
	public int getFrom_user_id() {
		return from_user_id;
	}
	
	public void setFrom_user_id(int from_user_id) {
		this.from_user_id = from_user_id;
	}
	
	public int getTo_user_id() {
		return to_user_id;
	}
	
	public void setTo_user_id(int to_user_id) {
		this.to_user_id = to_user_id;
	}
	
	public int getOperate() {
		return operate;
	}
	
	public void setOperate(int operate) {
		this.operate = operate;
	}
	
	// /end class
}
